module.exports = function ($scope, $resource,tourgroup_code,flag, $state, $http, FileUploader, toaster) {
      var tourgroup_code = flag ? {'flag': true} : tourgroup_code;
      console.log('----------utillllllllllllllllllllll------------')
      console.log(tourgroup_code)
      var para = {}
      $scope.infolist = []
      // var info = {}
      // $scope.info = {}
      var loadpara = {
        'tourgroup_code':tourgroup_code
      }
      $scope.load = function(tourgroup_code) {
        $resource('/api/ac/ggc/tourGroupAfter/getTGroupAndAddress', {}, {}).save(loadpara,function (res) {
          $scope.info = res.data.groupbody;
          $scope.time.date = $scope.str2date(res.data.groupbody.start_time);
          $scope.infolist = res.data.addressbody;
          console.log($scope.info);
        });
      }
      $scope.load();

      
      /* 修改数据处理 */
      // var updlist = []
      // $scope.upd = function(id){
      //   var upddata = {}
      //   updata = $scope.infolist[id]
      //   updlist.splice(id,1,updata);
      // }
      /* 准备传参数组para */
      
      $scope.save = function() {
        para = {
          'info': $scope.info,
          'infolist' : $scope.infolist
        }
        $scope.info.start_time = $scope.date2str($scope.time.date._d)
        console.log(para);
        $resource('/api/ac/ggc/tourGroupAfter/updateTGroup', {}, {}).save(para,function (res) {
          if(res.errcode !=0) {
            toaster.error({ title: "提示", body: res.errmsg });
          }
          else{
            toaster.success({title: "提示", body: "修改成功！"});
            console.log(res);
            $modalInstance.close();
          }
        });
      }
      $scope.time = {
        'date' : '',
        'options' : {
            //  format: "YYYY-MM-DD",
            locale : 'zh-cn',
            showClear: true  ,
            //  clearBtn:true
        }
      }
      $scope.add = function() {
        
        $scope.infolist.push({
          center_name : '',
          center_log : '',
          center_lat : '',
          center_no: ''
        })
        $scope.remove = function (index) {
          $scope.infolist.splice(index, 1);
      }
    }


    $scope.str2date = function (strDate){
      if(angular.isString(strDate))
      {
          var objDate = new Date(Date.parse(strDate.replace(/-/g, "/")));

          return objDate;
      }
      else
      {
          return '错误格式';
      }
    }

    $scope.date2str = function date2str(d) {
      if (d === undefined) {
          return "";
      }
      var month = (d.getMonth() + 1).toString();
      var day = d.getDate().toString();
      if (month.length == 1) month = '0' + month;
      if (day.length == 1) day = '0' + day;
      return d.getFullYear() + "-" + month + "-" + day;
  }
        }